#include <iostream>
#include <string>
#include <cstring>

int main()
{
    using namespace std;

    char animal[30] = "aquawius";
    char *ps;
    ps = animal;

    cout << animal << " at " << (unsigned int *)animal << endl;
    cout << ps << " at " << (unsigned int *)ps << endl;
    //上面的东西,很明显两个指针指向的是同一个地址

    //怎么样使用指针重新开辟一块区域
    ps = new char[strlen(animal) + 1]; //利用new重新分配一个新的符合大小的块内存  +1是因为需要在其中加入 '\0'
    //这里如果ps指针被更改,将会失去访问这个变量的唯一途径

    strcpy(ps, animal);
    //或者使用strncpy()函数指定一个数量
    strncpy(ps, animal, strlen(animal) + 1);

    cout << animal << " at " << (unsigned int *)animal << endl;
    cout << ps << " at " << (unsigned int *)ps << endl;

    //得到的输出
    // aquawius at 0x61fdf0
    // aquawius at 0x61fdf0
    // aquawius at 0x61fdf0
    // aquawius at 0x7c3f20

    return 0;
}